<template>
  <div class="body1" style="padding-top:10px;">
    <div class="form_select">
      <div>
          <el-input class="select_input" size="small" v-model="form.name" placeholder="项目名称"></el-input>
          <el-button type="primary"  size="small" @click="getList">搜索</el-button>
      </div>
      <div class="select_right">
          <el-button type="primary"  size="small" @click="dialog('cardAdd')">+添加项目</el-button>
      </div>
    </div>
    <cardTable :list="list" @func="dialogClose"></cardTable>
    <cardAdd :show="cardAddShow" :goods="goods" @func="dialogClose"></cardAdd>
    <goodsTable :show="goodsTableShow" :goods="goodsTable" @func="dialogClose"></goodsTable>
    <!--<cardEdit :show="cardEditShow" @func="dialogClose" :form="cardEdit" :goods="goods"></cardEdit>-->
    </div>
   </div>


</template>
 
<script>
import cardAdd from "./cardAdd"
//import cardEdit from "./cardEdit"
import cardTable from "./cardTable"
import goodsTable from "./goodsTable"
export default {
  name: "Project",
  data() {
    return {
      list:[],
      form:{},
      cardAddShow:false,
      goodsTableShow:false,
      //cardEditShow:false,
      goodsTable:[],
      goods:[
        {id:0,name:'请选择'}
      ],
      cardEdit:{}
    };
  },
  components: {
    "cardAdd": cardAdd,
    //"cardEdit": cardEdit,
    "cardTable": cardTable,
    "goodsTable":goodsTable
  },
  created: function() {
    this.getList()
  },
  methods: {
    getList:function(){
      this.form.oa_id = localStorage.getItem('oa_id')
      var that = this
      this.$get('pc/card/name',this.form).then((res) => {
        that.list = res.data
      })
    },
    dialog:function(key){
      if(key == 'cardAdd'){
        if(this.goods.length == 1){
          this.getGoods()
        }
      }
      this[key+'Show'] = true
    },
    dialogClose:function(data){
      this[data.key+'Show'] = !this[data.key+'Show']
      if(data.key == 'cardEdit'){
        if(this.goods.length == 1){
          this.getGoods()
        }
      }

      if(data.type){
        this.getList()
      }

      if(data.item){
        this[data.key] = data.item
      }
    },
    getGoods:function(){
      var data = {
        oa_id:localStorage.getItem('oa_id')
      }
      var that = this
      this.$get('manage/goods/all',data).then((res) => {
        that.goods = that.goods.concat(res.data)
      })
    }
  }
};
</script>
<style>
</style>